﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Sprout.Repository.Options;
using System.Collections.Generic;

namespace Sprout.Repository
{
    public static class DataExtenstions
    {
        /// <summary>
        /// 注入DataSource
        /// </summary>
        /// <param name="services"></param>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public static IServiceCollection AddDataSource(this IServiceCollection services, IConfiguration configuration)
        {
            var connectionSettings = configuration.GetSection("DbConnectSettings").Get<List<ConnectionSetting>>();
            return services.AddDataSource(connectionSettings);
        }

        /// <summary>
        /// 注入DataSource
        /// </summary>
        /// <param name="services"></param>
        /// <param name="connectionSettings"></param>
        /// <returns></returns>
        public static IServiceCollection AddDataSource(this IServiceCollection services, IList<ConnectionSetting> connectionSettings)
        {
            DataSetting.Instance.Initialize(services, connectionSettings);
            return services;
        }
    }
}
